<script>
	var url;
	$(document).ready(function(){
		
		newData = function (){
			$('#dialog-pembobotan').dialog({
				title: 'Input Pembobotan Nilai',
				width: $(window).width() * 0.8,
				height: $(window).height() * 0.99,
				closed: true,
				cache: false,
				href: base_url+'pembobotan/add/',
				modal: true
			});
			 
			$('#dialog-pembobotan').dialog('open');
			url = base_url+'pembobotan/save';
		}
		// end newData
		
		// load grid
		$(function(){
			$('#dg').datagrid({url:"<?=base_url()?>pembobotan/grid"});	
			//$('#dg').datagrid('enableFilter'); 			
		});	
		
		// onchange
		$('#s_kd_fakultas').change(function(){
			$('#s_kd_prodi').load(base_url+'prosedur/getProdibyFakultas/'+$('#s_kd_fakultas').val());
		});
		
		$('#s_kd_prodi').change(function(){
			$('#s_kd_kurikulum').load(base_url+'prosedur/getKurikulumbyProdi/'+$('#s_kd_prodi').val());
		});
		
		$('#s_kd_kurikulum').change(function(){
			$('#s_kd_matakuliah').load(base_url+'prosedur/getMatakuliah/'+$('#s_kd_kurikulum').val());
		});
		
		$('#s_kd_matakuliah').change(function(){
			$('#s_kd_dosen').load(base_url+'prosedur/getDosenbyProdiNilai/'+$('#s_kd_matakuliah').val());
		});
		
		$('#s_kd_dosen').change(function(){
			$('#s_kd_kelas').load(base_url+'prosedur/getKelasbyDosenNilai/'+$('#s_kd_dosen').val());
		});
		
		// filter
		filter = function(){
			$('#dg').datagrid('load',{
				kd_prodi : $('#s_kd_prodi').val(),
				kd_kurikulum : $('#s_kd_kurikulum').val(),
			});
			//$('#dg').datagrid('enableFilter');
		}
		
		//# Tombol Bawah
		$(function(){
			var pager = $('#dg').datagrid().datagrid('getPager');	// get the pager of datagrid
			pager.pagination({
				buttons:[
				<?if($this->mdl_auth->CekAkses(array('menu_id'=>39, 'policy'=>'ADD'))){?>
					{
						iconCls:'icon-edit',
						text:'Edit Data',
						handler:function(){
							newData();
						}
					},
					{
						iconCls:'icon-excel',
						text:'Export EXCEL',
						handler:function(){
							window.open('<?=base_url().'pembobotan/laporan_excel'?>');
						}
					}
				<?}?>
				]
			});			
		});
		
	});
</script>

<table id="dg" title="Daftar Pembobotan Nilai" data-options="
			rownumbers:true,
			singleSelect:true,
			autoRowHeight:false,
			pagination:true,
			pageSize:30,
			fit:true,
			toolbar:'#toolbar',
			">
	<thead>
		<tr>
			<!--<th field="tahun_penerimaan" sortable="true" width="80">Tahun Penerimaan</th> -->
			<th field="id_krs_detail" hidden="true" sortable="false" width="40">ID </th>
			<th field="kd_matakuliah" sortable="true" width="100">Kode Matakuliah</th>
			<th field="nama_matakuliah" sortable="true" width="200">Nama Matakuliah</th>
			<th field="bobot_nilai_tugas" sortable="true" width="120">Bobot Nilai Tugas</th>
			<th field="bobot_nilai_uts" sortable="true" width="120">Bobot Nilai UTS</th>
			<th field="bobot_nilai_uas" sortable="true" width="120">Bobot Nilai UAS</th>
			<th field="bobot_presensi" sortable="true" width="120">Bobot Presensi</th>
			<th field="bobot_praktikum" sortable="true" width="120">Bobot Praktikum</th>	
		</tr>
	</thead>
</table>
<div id="toolbar" style="padding:5px;height:auto">
	<div class="fsearch">
		<table>
			<tr>
			<td>Fakultas</td>
			<td>: 
				<select id="s_kd_fakultas" name="s_kd_fakultas" style="width:200px;">
					<?=$this->mdl_prosedur->OptionFakultas();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Prodi</td>
			<td>: 
				<select id="s_kd_prodi" name="s_kd_prodi" style="width:200px;">
					<?=$this->mdl_prosedur->OptionProdi();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>Kurikulum</td>
			<td>: 
				<select id="s_kd_kurikulum" name="s_kd_kurikulum" style="width:200px;">
					<?=$this->mdl_prosedur->OptionKurikulum();?>
				</select>
			</td>
			<td>&nbsp;</td>
			<td>&nbsp;&nbsp;<a href="#" onclick="filter()" class="easyui-linkbutton" iconCls="icon-search">Filter</a></td>
			<td>&nbsp;</td>
			</tr>
		</table>
	</div>
</div>
<div id="dialog-pembobotan" class="easyui-dialog" style="width:400px;height:150px" closed="true" buttons="#dlg-buttons-sap">
		
	</div>
	<div id="dlg-buttons-sap">
		<a href="#" class="easyui-linkbutton" iconCls="icon-ok" onclick="save_bobot()">Save</a>
		<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dialog-pembobotan').dialog('close')">Cancel</a>
	</div>